#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PLL pair<ll,ll>
const ll N=1e5+10;
const ll M=1e5+10;
ll n,m,l,v;
struct Car{
	ll d,v,a;
}car[N];
ll p[M];
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t;
	cin>>t;
	while(t--){
		cin>>n>>m>>l>>v;
		for(ll i=1;i<=n;i++){
			cin>>car[i].d>>car[i].v>>car[i].a;
		}
		for(ll i=1;i<=m;i++){
			cin>>p[i];
		}
		ll cnt=0;
		ll vcnt=0;
		for(ll i=1;i<=n;i++){
			if(car[i].d>p[m] && car[i].v>v){
				vcnt++;
			}
			if(car[i].d>p[m]){
				continue;
			}
			if(car[i].v>v){
				cnt++;
			}
		}
		cout<<cnt<<" "<<m-bool(cnt)<<"\n";
	}
	return 0;
}